package de.hci.mid.socialmap.datamanagement;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class MysqlConnector implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Connection con = null;
	@SuppressWarnings("unused")
	private Statement stmt = null;
	private ResultSet rs = null;
	PreparedStatement checkUser = null;

	public MysqlConnector() throws ClassNotFoundException, SQLException {
		Class.forName("com.mysql.jdbc.Driver").getInterfaces();
		con = DriverManager.getConnection("jdbc:mysql://localhost/socialmap", "root", "doo0loo");
		stmt = con.createStatement();

		checkUser = con.prepareStatement("SELECT username, password FROM admins");

	}

	public boolean checkLogin(String username, String password) throws SQLException {
		rs = checkUser.executeQuery();
		while (rs.next()) {
			if (username.equals(rs.getString(1)) && password.equals(rs.getString(2))) {
				return true;
			}

		}
		return false;
	}

}
